<template>
    <main>
        <div class="top">
            <div class="writer">
                <img :src="thisWriter.avatar" alt="404" class="writerA">
                <div class="writerB">
                    <h2>{{thisWriter.username}}</h2>
                </div>
            </div>
            <div class="book">
                <ul>
                    <li v-for="item in writerBooks" :key="item._id">
                        <img :src="item.avatar" alt="404" class="writerA">
                        <div class="bookB">
                            <h4 @click="tobook(item._id)">{{item.bookname}}</h4>
                            <p>{{item.explain}}</p>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </main>
</template>

<script>
export default {
    created(){
        this.getThisWriter();
    },
    data(){
        return{
            thisWriter:{},
            writerBooks:[],
            
        }
    },
    methods:{
        async getThisWriter(){
            const {data:res} = await this.$http.get(`/writers/getAN/${this.$route.params.id}`)
            this.thisWriter = res.data;
            const {data:resa} = await this.$http.get(`books/thiswriterbooks/${this.$route.params.id}`)
            this.writerBooks = resa.data;
        },
        tobook(id){
            let routeUrl = this.$router.resolve(`/tobook/${id}`);
            window.open(routeUrl.href, "_blank");
        }
    }
}
</script>

<style lang="less" scoped>
    main{
        display: flex;
        height: 100%;
        width: 100%;
        justify-content: center;
    }
    li{
        list-style: none;
        display: flex;
        background-color: rgba(201, 197, 197, 0.13);
    }
    .top{
        min-height: 900px;
        width: 800px;
        display: flex;
        flex-direction: column;

    }
    .writer{
        height: 300px;
        width: 100%;
        display: flex;
        align-items: center;
        border-style: solid;
        border-width: 0px 0px 1px 0px;
    }
    .writerA{
        height: 100px;
        width: 100px;
        margin:0px 30px 0px 52px;
    }
    .writerB{
        height: 200px;
        flex:1;
    }
    .book{
        flex: 1;
    }
    .book ul{
        padding: 0px;
    }
    .book li{
        height: 150px;
        width: 100%;
        display: flex;
        align-items: center;
        border-style: solid;
        border-width: 0px 0px 1px 0px;
    }
    .book li img{
        height: 120px;
        width: 90px;
    }
    .bookB{
        height: 100%;
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    .bookB h4{
        margin-top: 15px;
        margin-bottom: 8px;
        
    }
    .bookB p{
        margin: 0;
        width: 88%;
    }
    h4:hover{
        color: blue;
        cursor:pointer
    }
</style>